package com.lee.lxl.idcard.activity;

import android.os.Bundle;
import android.util.Log;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.ab.http.AbHttpUtil;
import com.ab.http.AbRequestParams;
import com.ab.http.AbStringHttpResponseListener;
import com.lee.lxl.idcard.R;
import com.lee.lxl.idcard.urls.Urls;
import com.zhy.autolayout.AutoLayoutActivity;

import org.json.JSONException;
import org.json.JSONObject;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class WebscanActivity extends AutoLayoutActivity {

    @Bind(R.id.et_webscan)
    EditText etWebscan;
    @Bind(R.id.bt_webscan)
    Button btWebscan;
    @Bind(R.id.tv_idcard)
    TextView tvIdcard;

    private AbHttpUtil mAbHttpUtil = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_webscan);
        ButterKnife.bind(this);
        mAbHttpUtil = AbHttpUtil.getInstance(this);
        mAbHttpUtil.setTimeout(10000);
        mAbHttpUtil.setEncode("UTF-8");
    }

    @OnClick(R.id.bt_webscan)
    public void onClick() {
        // 绑定参数
        AbRequestParams params = new AbRequestParams();
        params.put("key", "3f49ac3b7275506b9fead9848edf7cf0");
        params.put("dtype", "json");
        params.put("domain",etWebscan.getText().toString());
        mAbHttpUtil.get(Urls.WEBSCAN, params, new AbStringHttpResponseListener() {
            @Override
            public void onSuccess(int i, String s) {
                tvIdcard.setText(s);
            }

            @Override
            public void onStart() {

            }

            @Override
            public void onFinish() {

            }

            @Override
            public void onFailure(int i, String s, Throwable throwable) {
                tvIdcard.setText(s);
            }
        });
    }
}
